﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ECare.BUS;
using DevExpress.Skins;

namespace ECare.Win.controls
{
    public partial class ucSettings : BaseModule
    {
        public ucSettings()
        {
            InitializeComponent();

            pnlList.ItemSize = 100;
            int width = pnlList.ItemSize * 2;
            ((ITileControl)pnlList).Properties.LargeItemWidth = width;
            pnlList.Width = width + pnlList.Padding.Horizontal + SystemInformation.VerticalScrollBarWidth + 2;
        }
        public override string ModuleCaption { get { return "Settings"; } }

        internal override void InitModule(DevExpress.Utils.Menu.IDXMenuManager manager, object data)
        {
            base.InitModule(manager, data);

            //Load the tile.
            var settings = ModulesHelper.GetMenuItems().FirstOrDefault(a => a.ModuleId == 7);
            var group = new TileGroup();
            foreach (var setting in settings.Children)
            {
                var item = new TileItem { IsLarge = true };
                item.Appearance.BackColor = Color.FromArgb(102, 102, 102);
                item.AppearanceSelected.BackColor = CommonSkins.GetSkin(LookAndFeel.ActiveLookAndFeel).Colors["Highlight"];

                item.BackgroundImageScaleMode = TileItemImageScaleMode.NoScale;
                item.BackgroundImageAlignment = TileItemContentAlignment.MiddleRight;

                item.Tag = setting;
                item.Text = setting.ModuleName;
                item.Tag = setting.frmType;

                item.Appearance.BackColor = setting.BackColor;
                item.Appearance.BackColor2 = setting.BackColor2;
                item.Appearance.BorderColor = setting.BorderColor;


                item.AppearanceSelected.BackColor = setting.BackColor;
                item.AppearanceSelected.BackColor2 = setting.BackColor2;
                item.AppearanceSelected.BorderColor = Color.Black;
                item.AppearanceSelected.Font = new System.Drawing.Font("Tahoma", 13F);



                item.ImageAlignment = TileItemContentAlignment.MiddleCenter;

                item.Appearance.Font = new System.Drawing.Font("Tahoma", 11F);

                if (setting.ModuleId == 77)
                {
                    item.Image = global::ECare.Win.Properties.Resources.new_32x32;
                }
                else if (setting.ModuleId == 71)
                {
                    item.Image = global::ECare.Win.Properties.Resources.fillbackground_32x32;
                }
                else if (setting.ModuleId == 72)
                {
                    item.Image = global::ECare.Win.Properties.Resources.contact_32x32;
                }
                else
                {

                }

                item.ImageToTextAlignment = TileControlImageToTextAlignment.Top; item.ItemClick += item_ItemClick;
                group.Items.Add(item);
            }

            this.pnlList.Groups.Add(group);


        }

        void item_ItemClick(object sender, TileItemEventArgs e)
        {
            //throw new NotImplementedException();

            this.panelControl1.Controls.Clear();
            var frm = e.Item.Tag.ToString();
            var usercontrol = Activator.CreateInstance(typeof(frmMain).Assembly.GetType(frm)) as UserControl;
            usercontrol.Dock = DockStyle.Fill;
            this.panelControl1.Controls.Add(usercontrol);



        }
    }
}
